package com.hdu.pyl.service.hot;

import com.hdu.pyl.mappper.NewsMapper;
import com.hdu.pyl.mappper.TagsMapper;
import com.hdu.pyl.pojo.News;
import com.hdu.pyl.pojo.NewsTags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class HotServiceImpl implements HotService{
    @Autowired
    private NewsMapper newsMapper;
    @Autowired
    private TagsMapper tagsMapper;
    @Override
    public List<News> recommendWithNum(int limit, Date startTime) {
        List<News> news=newsMapper.recommendWithNum(limit,startTime);
        for (int i = 0; i < news.size(); i++) {
            news.get(i).setNewsTags(getTag(news.get(i).getId()));
        }
        return news;
    }
    private NewsTags getTag(Integer newsId){
        return tagsMapper.findByNewsId(newsId);
    }
}
